<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qqmlfileselector.cpp -->
  <title>QQmlFileSelector  类 | Qt QML 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtqml-index.html">Qt QML</a></td><td ><a href="qtqml-module.html">C++ 类</a></td><td >QQmlFileSelector</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtqml-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#public-functions">公用函数</a></li>
<li class="level1"><a href="#static-public-members">静态共用成员</a></li>
<li class="level1"><a href="#details">详细描述</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QQmlFileSelector类</h1>
<!-- $$$QQmlFileSelector-brief -->
<p>用于将<a href="../qtcore/qfileselector.html">QFileSelector</a> 应用于QML文件加载的类。 <a href="#details">更多…</a></p>
<!-- @@@QQmlFileSelector -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> 头文件：</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QQmlFileSelector&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += qml</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign">  Qt 5.2</td></tr><tr><td class="memItemLeft rightAlign topAlign">继承自：</td><td class="memItemRight bottomAlign"> <a href="../qtcore/qobject.html">QObject</a></td></tr></table></div><ul>
<li><a href="qqmlfileselector-members.html"></a></li>
<li><a href="qqmlfileselector-obsolete.html">废弃的成员</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">公用函数</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmlfileselector.html#QQmlFileSelector">QQmlFileSelector</a></b>(QQmlEngine *<i>engine</i>, QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qqmlfileselector.html#dtor.QQmlFileSelector">~QQmlFileSelector</a></b>() override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QFileSelector *</td><td class="memItemRight bottomAlign"><b><a href="qqmlfileselector.html#selector">selector</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlfileselector.html#setExtraSelectors">setExtraSelectors</a></b>(QStringList &amp;<i>strings</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlfileselector.html#setExtraSelectors-1">setExtraSelectors</a></b>(const QStringList &amp;<i>strings</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlfileselector.html#setSelector">setSelector</a></b>(QFileSelector *<i>selector</i>)</td></tr>
</table></div>
<ul>
<li class="fn">从<a href="../qtcore/qobject.html#public-functions">QObject</a>继承的31个公共函数</li>
</ul>
<a name="static-public-members"></a>
<h2 id="static-public-members">静态共用成员</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QQmlFileSelector *</td><td class="memItemRight bottomAlign"><b><a href="qqmlfileselector.html#get">get</a></b>(QQmlEngine *<i>engine</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const QMetaObject </td><td class="memItemRight bottomAlign"><b><a href="qqmlfileselector.html#staticMetaObject-var">staticMetaObject</a></b></td></tr>
</table></div>
<ul>
<li class="fn">从<a href="../qtcore/qobject.html#static-public-members">QObject</a>继承的9个静态公共成员</li>
</ul>
<h3>额外的继承成员</h3>
<ul>
<li class="fn">从<a href="../qtcore/qobject.html#properties">QObject</a>继承的1个属性</li>
<li class="fn">从<a href="../qtcore/qobject.html#public-slots">QObject</a>继承的1个公共槽</li>
<li class="fn">从<a href="../qtcore/qobject.html#signals">QObject</a>继承的2个信号</li>
<li class="fn">从<a href="../qtcore/qobject.html#protected-functions">QObject</a>继承的9个受保护的函数</li>
</ul>
<a name="details"></a>
<!-- $$$QQmlFileSelector-description -->
<div class="descr">
<h2 id="details">详细描述</h2>
<p>用于将<a href="../qtcore/qfileselector.html">QFileSelector</a>应用于QML文件加载的类。</p>
<p><a href="qqmlfileselector.html">QQmlFileSelector</a>将自动将<a href="../qtcore/qfileselector.html">QFileSelector</a> 应用于qml文件和资产路径。</p>
<p>使用方法如下:</p>
<pre class="cpp">

  <span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> engine;
  <span class="type"><a href="qqmlfileselector.html#QQmlFileSelector">QQmlFileSelector</a></span><span class="operator">*</span> selector <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qqmlfileselector.html#QQmlFileSelector">QQmlFileSelector</a></span>(<span class="operator">&amp;</span>engine);

</pre>
<p>然后你可以像这样交换文件:</p>
<pre class="cpp">

  main<span class="operator">.</span>qml
  Component<span class="operator">.</span>qml
  asset<span class="operator">.</span>png
  <span class="operator">+</span>unix<span class="operator">/</span>Component<span class="operator">.</span>qml
  <span class="operator">+</span>mac<span class="operator">/</span>asset<span class="operator">.</span>png

</pre>
<p>在本例中，main.qml通常将Component.qml用于组件类型。但是在unix平台上，将使用unix选择器，并使用+unix/Component.qml版本。注意，这类似于用+unix/Component.qml替换Component.qml，因此在使用Component.qml时，不需要根据选择的版本更改任何路径。</p>
<p>例如，要传递&quot;asset.png&quot;文件路径，您可以像在所有main.qml、Component.qml和+linux/Component.qml中引用&quot;asset.png&quot;一样引用它。在所有情况下，它将被替换为mac平台上的+mac/asset.png。</p>
<p>有关可用选择器的列表，请参见<code>QFileSelector</code>。</p>
<p>您的平台还可能提供额外的选择器供您使用。正如<a href="../qtcore/qfileselector.html">QFileSelector</a>所指定的，用于选择的目录必须以“+”字符开头，因此除非您的项目中有具有这样名称的目录，否则不会意外触发此功能。</p>
<p>如果在引擎上设置了新的<a href="qqmlfileselector.html">QQmlFileSelector</a>，则将替换旧的。使用<a href="qqmlfileselector.html#get">QQmlFileSelector::get</a>() 查询或使用现有实例。</p>
</div>
<!-- @@@QQmlFileSelector -->
<div class="func">
<h2>成员函数文档</h2>
<!-- $$$QQmlFileSelector[overload1]$$$QQmlFileSelectorQQmlEngine*QObject* -->
<h3 class="fn" id="QQmlFileSelector"><a name="QQmlFileSelector"></a>QQmlFileSelector::<span class="name">QQmlFileSelector</span>(<span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> *<i>engine</i>, <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p>使用父对象<i>parent</i>创建一个新的<a href="qqmlfileselector.html">QQmlFileSelector</a>，其中包含自己的<a href="../qtcore/qfileselector.html">QFileSelector</a>. <i>engine</i>，它是您希望应用文件选择器的<a href="qqmlengine.html">QQmlEngine</a>。它还将拥有<a href="qqmlfileselector.html">QQmlFileSelector</a>的所有权。</p>
<!-- @@@QQmlFileSelector -->
<!-- $$$~QQmlFileSelector[overload1]$$$~QQmlFileSelector -->
<h3 class="fn" id="dtor.QQmlFileSelector"><a name="dtor.QQmlFileSelector"></a><code>[override virtual] </code>QQmlFileSelector::<span class="name">~QQmlFileSelector</span>()</h3>
<p>销毁<a href="qqmlfileselector.html">QQmlFileSelector</a>对象。</p>
<!-- @@@~QQmlFileSelector -->
<!-- $$$get[overload1]$$$getQQmlEngine* -->
<h3 class="fn" id="get"><a name="get"></a><code>[static] </code><span class="type"><a href="qqmlfileselector.html#QQmlFileSelector">QQmlFileSelector</a></span> *QQmlFileSelector::<span class="name">get</span>(<span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> *<i>engine</i>)</h3>
<p>获取目标<i>engine</i>上当前活动的<a href="qqmlfileselector.html">QQmlFileSelector</a>。</p>
<!-- @@@get -->
<!-- $$$selector[overload1]$$$selector -->
<h3 class="fn" id="selector"><a name="selector"></a><span class="type"><a href="../qtcore/qfileselector.html">QFileSelector</a></span> *QQmlFileSelector::<span class="name">selector</span>() const</h3>
<p>返回<a href="../qtcore/qfileselector.html">QFileSelector</a>使用的<a href="qqmlfileselector.html">QQmlFileSelector</a>实例。</p>
<p>这个函数是在Qt 5.7中引入的。</p>
<p><b>参见</b><a href="qqmlfileselector.html#setSelector">setSelector</a>()。</p>
<!-- @@@selector -->
<!-- $$$setExtraSelectors[overload1]$$$setExtraSelectorsQStringList& -->
<h3 class="fn" id="setExtraSelectors"><a name="setExtraSelectors"></a><span class="type">void</span> QQmlFileSelector::<span class="name">setExtraSelectors</span>(<span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> &amp;<i>strings</i>)</h3>
<p>将<i>strings</i>中包含的额外选择器添加到当前使用的<a href="../qtcore/qfileselector.html">QFileSelector</a> 。当您只需要使用额外的选择器就可以避免创建自己的<a href="../qtcore/qfileselector.html">QFileSelector</a> 实例时，请使用此选项。</p>
<!-- @@@setExtraSelectors -->
<!-- $$$setExtraSelectors$$$setExtraSelectorsconstQStringList& -->
<h3 class="fn" id="setExtraSelectors-1"><a name="setExtraSelectors-1"></a><span class="type">void</span> QQmlFileSelector::<span class="name">setExtraSelectors</span>(const <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> &amp;<i>strings</i>)</h3>
<p>将<i>strings</i>中包含的额外选择器添加到当前使用的<a href="../qtcore/qfileselector.html">QFileSelector</a> 。当您只需要使用额外的选择器就可以避免创建自己的<a href="../qtcore/qfileselector.html">QFileSelector</a> 实例时，请使用此选项。</p>
<!-- @@@setExtraSelectors -->
<!-- $$$setSelector[overload1]$$$setSelectorQFileSelector* -->
<h3 class="fn" id="setSelector"><a name="setSelector"></a><span class="type">void</span> QQmlFileSelector::<span class="name">setSelector</span>(<span class="type"><a href="../qtcore/qfileselector.html">QFileSelector</a></span> *<i>selector</i>)</h3>
<p>将<a href="../qtcore/qfileselector.html">QFileSelector</a> 实例设置为选择器，以便<a href="qqmlfileselector.html">QQmlFileSelector</a>使用。<a href="qqmlfileselector.html">QQmlFileSelector</a>不拥有新<a href="../qtcore/qfileselector.html">QFileSelector</a>的所有权。要重置<a href="qqmlfileselector.html">QQmlFileSelector</a>以使用其内部<a href="../qtcore/qfileselector.html">QFileSelector</a>实例，请调用setSelector(0)。</p>
<p><b>参见</b><a href="qqmlfileselector.html#selector">selector</a>()。</p>
<!-- @@@setSelector -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
